package com.keli.dt.model.rowmapper;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.keli.dt.algorithm.LaneReportAlgo;
import com.keli.dt.model.LaneReport;

public class LaneReportRowMapper implements RowMapper {

	@Override
	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		LaneReport lr = new LaneReport();
		lr.setDETECT_CLASS(rs.getString("DETECT_CLASS"));
		lr.setDETECT_ID(rs.getString("sbbh"));
		lr.setROAD_ID(new BigDecimal(rs.getString("SECTIONID")));	// 数据库路段编号类型不一致
		lr.setLANE(rs.getString("cdbh"));
		lr.setVEHICLE_CLASS(rs.getString("HPZL"));
		String collectDateTime = rs.getString("COLLEC_DATETIME");
		lr.setCOLLEC_TIME(collectDateTime);
		lr.setCOLLEC_DATETIME(collectDateTime);
		lr.setVOLUME(rs.getBigDecimal("VOLUME"));
		lr.setSPEED(rs.getBigDecimal("SPEED"));
		
		String den = LaneReportAlgo.calculateDensity(lr.getVOLUME(), lr.getSPEED());
		lr.setDENSITY(den);
		return lr;
	}
}
